import { BasicColumn, FormSchema } from '/@/components/Table';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';
import { defaultRule, rules } from '@/utils/common/validator';
import { apiGetDeptsDropdown } from '@/api/http/system/senior/depts/depts.api';
import { userRemarkFormItem, userStatusFormItem } from '@/settings/ShareFormItem';
import { apiPostWarehouseCheckNumberIsUnique } from '@/api/http/system/basic/warehouse/warehouse.api';

export const useWarehouseListColumns = (): BasicColumn[] => {
  return [
    { title: '仓库名称', dataIndex: 'name' },
    { title: '仓库编号', dataIndex: 'number' },
    { title: '所属组织', dataIndex: 'deptName' },
    { title: '联系人员', dataIndex: 'contacts' },
    { title: '联系电话', dataIndex: 'tel' },
    { title: '仓库地址', dataIndex: 'addr' },

    userStatusColumn(),
    userRemarksColumn(),
  ];
};

export const useWarehouseListSearchForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '仓库名称', component: 'Input' },
    { field: 'number', label: '仓库编号', component: 'Input' },
    { field: 'contacts', label: '联系人员', component: 'Input' },
    { field: 'tel', label: '联系电话', component: 'Input' },
    { field: 'addr', label: '仓库地址', component: 'Input' },
  ];
};

export const useWarehouseAddSchemaForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '仓库名称', component: 'Input' },
    { field: 'number', label: '仓库编号', component: 'Input' },
    { field: 'deptId', label: '组织结构', component: 'Input' },
    { field: 'contacts', label: '联系人员', component: 'Input' },
    { field: 'tel', label: '联系电话', component: 'Input' },
    { field: 'addr', label: '仓库地址', component: 'Input' },
    { field: 'remark', label: '备注信息', component: 'Input' },
    { field: 'status', label: '状态', component: 'Input' },
  ];
};

export const useWarehouseUpdateSchemaForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '仓库名称', component: 'Input', rules: defaultRule() },
    {
      field: 'number',
      label: '仓库编号',
      component: 'Input',
      dynamicRules: ({ model, schema }) =>
        rules.uniqueFieldValidation(apiPostWarehouseCheckNumberIsUnique, 'id', schema, model, true),
    },
    {
      field: 'deptId',
      label: '组织结构',
      component: 'ApiTreeSelect',
      required: true,
      componentProps: { api: apiGetDeptsDropdown },
    },
    { field: 'contacts', label: '联系人员', component: 'Input' },
    {
      field: 'tel',
      label: '联系电话',
      component: 'Input',
      rules: [rules.validateNotEmpty('mobile', '手机号格式输入有误')],
    },
    {
      field: 'addr',
      label: '仓库地址',
      component: 'Input',
      rules: [{ max: 200, message: '最多输入200个字符' }],
    },

    userStatusFormItem(),
    userRemarkFormItem(),
    { field: 'id', label: '仓库id', component: 'Input', show: false },
  ];
};
